import os
from threading import Thread
from task import a6 as tpjx, b4 as shrw, c4 as task_c
from webs import main_web_service
from utils import doc_util, read_config

__author__ = 'Administrator'


# 启动 web 服务
def func1(name):
    print(f"{name}开始")
    main_web_service.run()
    print(f"{name}结束")


# 开启均线监控定时任务
def func2(name):
    print(f"{name}开始")
    tpjx.monitor_up_down()
    print(f"{name}结束")


# 启动 natapp
def func3(name):
    print(f"{name}开始")
    # natapp_service.start()
    print(f"{name}结束")


# 记录当前线程-重启项目使用
def func4(name):
    print(f"{name}开始")
    # start_stop_service.record_pid()
    print(f"{name}结束")


# 启动页面线程
def func5(name):
    print(f"{name}开始")
    # main_web.main()
    print(f"{name}结束")


# 启动数据刷新定时任务
def func6(name):
    print(f"{name}开始")
    shrw.fresh_data()
    print(f"{name}结束")


# 启动数据刷新定时任务
def func7(name):
    print(f"{name}开始")
    task_c.start_task()
    print(f"{name}结束")


if __name__ == '__main__':
    # 清空cache
    doc_util.del_path_all_files(os.path.join(read_config.data_path, 'utils', 'cache'))
    print('清理缓存文件完成')
    t1 = Thread(target=func1, args=("线程1-启动web服务",))
    # t2 = Thread(target=func2, args=("线程2-启动监控任务",))
    # t3 = Thread(target=func3, args=("线程3",))
    # t4 = Thread(target=func4, args=("线程4",))
    # t5 = Thread(target=func5, args=("线程5",))
    t6 = Thread(target=func6, args=("线程6-启动数据刷新",))
    t7 = Thread(target=func7, args=("线程7-启动新监控",))
    t1.start()
    # t2.start()
    # t3.start()
    # t4.start()
    # t5.start()
    t6.start()
    t7.start()
    print("主线程结束")
